package com.jubaozan.service.platform.controller;

import com.jubaozan.c3.framework.utils.ResultHolder;
import com.jubaozan.feign.level.vo.RuleVO;
import com.jubaozan.service.platform.decorator.TeamRegisterDecorator;
import com.jubaozan.service.platform.vo.StoreUserRelationVO;
import com.jubaozan.service.platform.vo.TeamInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @ClassName TeamRegisterController
 * @Description 团长入驻相关接口Controller
 * @Author SunWei
 * @Version 1.0
 **/
@Api(tags = {"团长入驻相关接口"}, value = "团长入驻相关接口")
@RestController
@RequestMapping("/team")
@Validated
public class TeamRegisterController {

    private final TeamRegisterDecorator teamRegisterDecorator;

    public TeamRegisterController(TeamRegisterDecorator teamRegisterDecorator) {
        this.teamRegisterDecorator = teamRegisterDecorator;
    }

    @ApiOperation(value = "平台、团长配置规则信息")
    @GetMapping("/queryRule")
    public ResultHolder<List<RuleVO>> queryRule(@ApiParam(value = "门店id") @RequestParam("storeId")  Long storeId,
                                                @ApiParam(value = "权重等级") @RequestParam("weight")  Integer weight){
        return ResultHolder.success(teamRegisterDecorator.queryRule(weight,storeId));
    }

    @ApiOperation(value = "保存升级规则信息")
    @PostMapping("/saveRule")
    public ResultHolder<List<RuleVO>> saveRule(@ApiParam(value = "门店id") @RequestParam("storeId")  Long storeId,
                                          @ApiParam(value = "权重等级") @RequestParam("weight")  Integer weight,
                                          @RequestBody List<RuleVO> rules){
        return ResultHolder.success(teamRegisterDecorator.saveRule(weight,storeId,rules));
    }

    @ApiOperation(value = "团长资料注册")
    @PostMapping("/register")
    public ResultHolder<Object> registerTeam(@Valid @RequestBody TeamInfoVO teamInfoVO){
        return ResultHolder.success(teamRegisterDecorator.register(teamInfoVO));
    }

    @ApiOperation(value = "查询此用户是否存在绑定关系")
    @PostMapping("/relation")
    public ResultHolder<StoreUserRelationVO> queryStoreUserRelation(@ApiParam(value = "门店id") @RequestParam("storeId")  Long storeId,
                                                                    @ApiParam(value = "用户id") @RequestParam("userId")  Long userId){
        return ResultHolder.success(teamRegisterDecorator.queryStoreUserRelation(storeId,userId));
    }

}
